package com.rabbiter.ordering.service;


import com.rabbiter.ordering.entity.OrderItem;
import com.rabbiter.ordering.mapper.OrderItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderItemService {
    @Autowired
    private OrderItemMapper orderItemMapper;

    public int createOrderItem(OrderItem orderItem) {
        return orderItemMapper.insert(orderItem);
    }

    public OrderItem getOrderItemById(Long id) {
        return orderItemMapper.selectById(id);
    }

    public List<OrderItem> getAllOrderItems() {
        return orderItemMapper.selectAll();
    }

    public int updateOrderItem(OrderItem orderItem) {
        return orderItemMapper.update(orderItem);
    }

    @Transactional
    public int deleteOrderItem(Long id) {
        return orderItemMapper.delete(id);
    }

    public List<OrderItem> getItemsByOrderId(Long orderId) {
        return orderItemMapper.selectByOrderId(orderId);
    }
}
